package capricornus.actor.attribute
{
	import capricornus.actor.events.ActorAttributeEvent;
	import capricornus.core.StageManager;
	
	import flash.events.EventDispatcher;

	[Event(name="nameChanged", type="capricornus.actor.events.ActorAttributeEvent")]
	public class ActorAttribute extends EventDispatcher
	{
		protected var _id:String;
		protected var _name:String;
		protected var _actionImagePath:String;           //人物动作图路径前缀，类似的有武器和坐骑
		
		protected var _hp:int;
		protected var _maxHp:int = int.MAX_VALUE;
		protected var _speed:Number;
		protected var _height:int;
		protected var _armor:uint;
		
		protected var _level:int;
		
		protected var _delayTime:int = 140;
		
		public function ActorAttribute()
		{
		}
		
		public function get id():String
		{
			return _id;
		}
		
		public function get name():String
		{
			return _name;
		}
		
		public function get level():int
		{
			return _level;
		}
		
		public function get actionImagePath():String
		{
			return _actionImagePath;
		}
		
		public function get hp():int
		{
			return _hp;
		}
		
		public function get maxHp():int
		{
			return _maxHp;
		}
		
		public function get speed():Number
		{
			return _speed;
		}
		
		public function get height():int
		{
			return _height;
		}
		
		public function get armor():uint
		{
			return _armor;
		}
		
		public function get delayTime():int
		{
			return _delayTime;
		}
		
		public function setID( value:String ):void
		{
			_id = value;
		}
		
		public function setName( value:String, sendEvent:Boolean=true ):void
		{
			if( _name != value )
			{
				_name = value;
				if( sendEvent ) dispatchEvent( new ActorAttributeEvent( ActorAttributeEvent.NAME_CHANGED ) ); 
			}
		}
		
		public function setLevel( value:int, sendEvent:Boolean=true ):void
		{
			if( _level != value )
			{
				_level = value;
				if( sendEvent ) dispatchEvent( new ActorAttributeEvent( ActorAttributeEvent.LEVEL_CHANGED ) ); 
			}
		}
		
		public function setActionImagePath( value:String, sendEvent:Boolean=true ):void
		{
			if( _actionImagePath != value )
			{
				_actionImagePath = value;
				if( sendEvent ) dispatchEvent( new ActorAttributeEvent( ActorAttributeEvent.ACTION_IMAGE_PATH_CHANGED ) ); 
			}
		}
		
		public function setHp( value:int, sendEvent:Boolean=true ):void
		{
			if( _hp != value )
			{
				_hp = value;
				if( _hp > _maxHp )
				{
					_hp = _maxHp;
				}
				if( sendEvent ) dispatchEvent( new ActorAttributeEvent( ActorAttributeEvent.HP_CHANGED ) );
			}
		}
		
		public function setMaxHp( value:int, sendEvent:Boolean=true ):void
		{
			if( _maxHp != value )
			{
				_maxHp = value;
				if( _hp > _maxHp )
				{
					_hp = _maxHp;
				}
				if( sendEvent ) dispatchEvent( new ActorAttributeEvent( ActorAttributeEvent.MAX_HP_CHANGED ) );
			}
		}
		
		/**
		 * 设置速度 
		 * @param value ps/s
		 * @param sendEvent
		 * 
		 */		
		public function setSpeed( value:Number, sendEvent:Boolean=true ):void
		{
			value = value/1000;
			
			if( _speed != value )
			{
				_speed = value;
				if( sendEvent ) dispatchEvent( new ActorAttributeEvent( ActorAttributeEvent.SPEED_CHANGED ) );
			}
		}
		
		public function setHeight( value:int, dispatchEvent:Boolean=true ):void
		{
			if( _height != value )
			{
				_height = value;
				if( dispatchEvent ) this.dispatchEvent( new ActorAttributeEvent( ActorAttributeEvent.HEIGHT_CHANGE ) );
			}
		}
		
		public function setArmor( value:uint, sendEvent:Boolean=true ):void
		{
			if( _armor != value )
			{
				_armor = value;
				if( sendEvent ) dispatchEvent( new ActorAttributeEvent( ActorAttributeEvent.ARMOR_CHANGED ) );
			}
		}
		
		public function setDelayTime( value:uint, sendEvent:Boolean=true ):void
		{
			if( _delayTime != value )
			{
				_delayTime = value;
				if( sendEvent ) dispatchEvent( new ActorAttributeEvent( ActorAttributeEvent.DELAY_TIME_CHANGED ) );
			}
		}
	}
}



